/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Bussiness;

import DatabaseAccess.DBHelper;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

/**
 *
 * @author Nlanh_BN
 */
public class NCC {
    private String MaNCC;
    private String TenNCC;
    private String Diachi;
    private String Masothue;
    private String Sotk;
    DBHelper conn = new DBHelper();

    public String getDiachi() {
        return Diachi;
    }

    public void setDiachi(String Diachi) {
        this.Diachi = Diachi;
    }

    public String getMaNCC() {
        return MaNCC;
    }

    public void setMaNCC(String MaNCC) {
        this.MaNCC = MaNCC;
    }

    public String getMasothue() {
        return Masothue;
    }

    public void setMasothue(String Masothue) {
        this.Masothue = Masothue;
    }

    public String getSotk() {
        return Sotk;
    }

    public void setSotk(String Sotk) {
        this.Sotk = Sotk;
    }

    public String getTenNCC() {
        return TenNCC;
    }

    public void setTenNCC(String TenNCC) {
        this.TenNCC = TenNCC;
    }
    
    public NCC(){}
    public NCC(String MaNCC, String TenNCC, String diachi, String Masothue, String Sotk){
        this.setMaNCC(MaNCC);
        this.setTenNCC(TenNCC);
        this.setDiachi(diachi);
        this.setMasothue(Masothue);
        this.setSotk(Sotk);
    }
    public int insertNCC(NCC a) throws SQLException
    {
        int i = 0;
        try{
            Vector v = new Vector();
            v.add(a.getMaNCC());
            v.add(a.getTenNCC());
            v.add(a.getDiachi());
            v.add(a.getMasothue());
            v.add(a.getSotk());
            i=conn.executeUpdate("sp_InsertNCC",v);
        }catch(SQLException ex){}
        return i;
    }
    public int updateNCC(NCC a) throws SQLException
    {
        DBHelper obj =new DBHelper();
        int i = 0;
        try{
            Vector v = new Vector();
            v.add(a.getMaNCC());
            v.add(a.getTenNCC());
            v.add(a.getDiachi());
            v.add(a.getMasothue());
            v.add(a.getSotk());
            i=obj.executeUpdate("sp_UpdateNCC",v);
        }catch(SQLException ex){}
        return i;
    }
    
    public int DelNCC(String MaNCC) throws SQLException
    {
        int i=0;
        try
        {
            Vector paramList=new Vector();
            paramList.add(MaNCC);            
            i=conn.executeUpdate("sp_DelNCC",paramList);
        }
        catch(SQLException sqlex)
        {
            
        }
        return i;
    }
    public Vector getAllNCC() throws SQLException
    {
        Vector v = new Vector();
        try 
        {
            ResultSet rs = conn.executeQuery("sp_getAllNCC");
            while(rs.next())
            {                  
                NCC b = new NCC();
                b.setMaNCC(rs.getString(1));
                b.setTenNCC(rs.getString(2));
                b.setDiachi(rs.getString(3));
                b.setMasothue(rs.getString(4));
                b.setSotk(rs.getString(5));
                v.add(b);                         
            }
        } 
        catch(SQLException sqle) 
        {            
        }
        return v;
    }
    public Vector getNCC_MaNCC(String MaNCC) throws SQLException
    {
        Vector v = new Vector();
        Vector v1 = new Vector();
        v1.add(MaNCC);
        try{
            ResultSet rs = conn.executeQuery("sp_getMaNCC", v1);
            while(rs.next()){
                NCC b = new NCC();
                b.setMaNCC(rs.getString(1));
                b.setTenNCC(rs.getString(2));
                b.setDiachi(rs.getString(3));
                b.setMasothue(rs.getString(4));
                b.setSotk(rs.getString(5));
                v.add(b);
            }
        }catch(SQLException sqle) {}
        return v; 
    }
    public Vector getNCC_TenNCC(String TenNCC) throws SQLException
    {
        Vector v = new Vector();
        Vector v1 = new Vector();
        v1.add(TenNCC);
        try{
            ResultSet rs = conn.executeQuery("sp_getTenNCC", v1);
            while(rs.next()){
                NCC b = new NCC();
                b.setMaNCC(rs.getString(1));
                b.setTenNCC(rs.getString(2));
                b.setDiachi(rs.getString(3));
                b.setMasothue(rs.getString(4));
                b.setSotk(rs.getString(5));
                v.add(b);
            }
        }catch(SQLException sqle) {}
        return v;
    }
}
